package com.itheima.xiancheng.homework.homework4;

import java.util.Random;

public class CJ1 implements Runnable {
    private MyBox box;

    public CJ1(MyBox box) {
        this.box = box;

    }


    @Override
    public void run() {
        Random r = new Random();
        synchronized ("abc") {
            while (box.getCount() < box.getPrizePool().length) {
                int index = r.nextInt(box.getPrizePool().length);
                if (box.getPrizePool()[index] != 0) {
                    System.out.println(Thread.currentThread().getName() + "抽出奖金" + box.getPrizePool()[index]);
                    box.getPrizePool()[index] = 0;
                    int count = box.getCount();
                    box.setCount(count+1);
                    "abc".notify();
                    try {
                        "abc".wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
